package org.one.stone.soup.grfxML;

import java.util.Hashtable;
import java.util.Vector;

/*
 * Copyright 2000-2001 Wet-Wired.com Ltd.,
 * Portsmouth England
 * All rights reserved.
 */

/**
	*
	* @author Nik Cross
*/
public class GrfxMLLoader implements Runnable{

	private static Hashtable loading = new Hashtable();
	private GrfxMLEngine controller;
	private String url;
private GrfxMLLoader(GrfxMLEngine controller,String url) {
	super();

	this.controller = controller;
	this.url = url;

	new Thread(this,"grfxML Loader").start();
}
public static boolean isLoading(GrfxMLEngine engine) {
	Vector loaders = (Vector)loading.get(engine);
	if(loaders!=null)
	{
		if(loaders.size()>0)
		{
			return true;
		}
	}

	return false;
}
protected static void load(GrfxMLEngine controller,String url)
{
	createLoader(controller,url);
}
protected static void load(GrfxMLEngine controller,DataString url)
{
	createLoader(controller,url.getValue());
}
public void run()
{
	controller.loadPage(url);
	removeLoader(controller,this);
}

private static GrfxMLLoader createLoader(GrfxMLEngine engine,String url) {
	GrfxMLLoader loader = new GrfxMLLoader(engine,url);

	Vector loaders = (Vector)loading.get(engine);
	if(loaders==null)
	{
		loaders = new Vector();
		loading.put(engine,loaders);
	}

	return loader;
}

private static void removeLoader(GrfxMLEngine engine,GrfxMLLoader loader)
{
	Vector loaders = (Vector)loading.get(engine);
	if(loaders!=null)
	{
			loaders.remove( loader );
	}
}

}
